package hw20170814.q2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Dbutil {
	private Connection conn=null;
	private Statement stm=null;
	private ResultSet rs=null;
	
	String url="jdbc:mysql://localhost:3306/examsystem?useUnicode=true&characterEncoding=utf-8";
	String dbname="root";
	String dbpwd="123456";
	public Connection getConnection() throws ClassNotFoundException, SQLException{
		Class.forName("com.mysql.jdbc.Driver");

		return DriverManager.getConnection(url, dbname, dbpwd);
	}
	
	public void closeAll(){
		if (rs!=null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (stm!=null) {
			try {
				stm.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (conn!=null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
	}
}